package selcoursesys.service.impl;

import com.opensymphony.xwork2.ActionContext;
import selcoursesys.dao.CourseDAO;
import selcoursesys.dao.StudentDAO;
import selcoursesys.dao.impl.CourseDAOImpo;
import selcoursesys.dao.impl.StudentDAOImpl;
import selcoursesys.entity.CourseEntity;
import selcoursesys.entity.CourseInfo;
import selcoursesys.service.ShowCourseInfoService;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Lpbdz on 2017/4/13.
 */
public class ShowCourseInfoServiceImpl implements ShowCourseInfoService {
    public String showCourseInfo(String stuid,String ctype,String term){
        //通过学号获得专业id
        List<CourseInfo> courseInfos=new LinkedList<CourseInfo>();
        StudentDAO studentDAO=new StudentDAOImpl();
        String majorId=studentDAO.queryStudentMajor(stuid);
        //System.out.println("学生专业"+majorId);
        //根据专业号GET专业缩写
        String majorAb= GetMajorAb.getMajorAb(majorId);
        //System.out.println(majorAb);
        //根据专业缩写找到必修课，选修课，辅修课，和所有课程
        CourseDAO courseDAO=new CourseDAOImpo();
        List<CourseEntity> list=courseDAO.queryCourseAll(ctype,term,majorAb);
        Iterator iterator=list.iterator();
        while(iterator.hasNext()){
            CourseEntity courseEntity=(CourseEntity)iterator.next();
            System.out.println(courseEntity.getCoursename()+courseEntity.getTeacherEntity().getTname());
            InputCourseInfo.inputCourseInfo(courseInfos,courseEntity,stuid,ctype);
        }
        ActionContext.getContext().put("compinfo",courseInfos);
        return "success";
    }
}
